package arithmetic.sort;

import java.util.Arrays;
import java.util.Random;

public class SelectSortTest {

    public static void main(String[] args) {
        //声明一个数组
        int[] array = new int[10];
        //为这个数组随机填入整型数字
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(500);
        }

        System.out.print("原始数组  ：");
        System.out.println(Arrays.toString(array));
        SelectSortTest.selectSort(array);

        System.out.print("排序后数组  ：");
        System.out.println(Arrays.toString(array));
    }

    private static void selectSort(int[] array) {
        if (null == array) {
            return;
        }

        for (int i = 0; i < array.length-1; i++) {
            int temp = array[i];
            int index = 0;
            for (int j = i + 1; j < array.length; j++) {
                if (temp >= array[j]) {
                    temp = array[j];
                    index = j;
                }
            }
            array[index] = array[i];
            array[i] = temp;
        }
    }


}
